﻿using ProtoBuf;

namespace SyncCore.Sync.Models
{
    public enum MessageType : int
    {
        None,
        Boardcast,
        Heartbeat,
        FromServer,
        JoinRoom, // 加入房间。
        ReadySync, // 客户端告诉服务器，开始同步。开始同步后的状态就是进行RPC 
        RPC,
        Success,
        Failed,
        Waiting,
    }

    [ProtoContract]
    public class MessagePack
    {
        [ProtoMember(1, Options = MemberSerializationOptions.Required)]
        public MessageType Type { get; set; } = MessageType.None;

        [ProtoMember(2, Options = MemberSerializationOptions.Required)]
        public int FrameIndex { get; set; } = -1;

        [ProtoMember(3, Options = MemberSerializationOptions.Required)]
        public CommandMessagePack[] Commands { get; set; } = Array.Empty<CommandMessagePack>();

        public MessagePack()
        {

        }

        public MessagePack(MessageType type, int frameIndex, string sender, string content)
        {
            Type = type;
            FrameIndex = frameIndex;
            Commands = new CommandMessagePack[] { new CommandMessagePack(sender, content) };
        }
    }
}
